<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=no" />
		<meta name="format-detection" content="telephone=no, address=no, email=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<meta name="misapplication-tap-highlight" content="no" />
		<meta name="HandheldFriendly" content="true" />
		<link rel="stylesheet" href="../../css/mui.min.css" type="text/css" charset="utf-8" />
		<link rel="stylesheet" href="../../css/style.css" type="text/css" charset="utf-8" />
		<link rel="stylesheet" href="../../css/product.css" type="text/css" charset="utf-8" />
		<style> p{ margin-bottom: 0px; }  .mui-table-view .mui-table-view-cell { margin-bottom: 0.14rem; background: #fff; border-left:0.06rem solid #0ab0e4}.mui-table-view .mui-table-view-cell.stop{border-left-color:#999}  .mui-table-view .mui-table-view-cell p { line-height: 1; color: #666; } .addWay { width: 1.86rem; display: inline-block; width: 1.86rem; display: inline-block; height: 0.65rem; padding: 0px; line-height: 0.65rem; }  .mui-icon-search { position: absolute; right: 0; line-height: 0.65rem; }  #searchValue { height: 0.65rem; line-height: 0.65rem; width: 90%; padding: 0px; padding-left: 3px; border-radius: 0; margin: 0px; border: none; } </style>
	</head>
	<body>
		<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
				<div class="mui-scroll">
					<!--数据列表-->
					<ul class="mui-table-view mui-table-view-chevron  plist" id="jxsList" style="margin:0px;margin-top:0.4rem;">
						
					</ul>
				</div>
			</div>
			
			
		<script src="../../js/resize.js"></script>
		<script src="../../js/mui.min.js"></script>
		<script src="../../js/ajaxFun.js"></script>
	 
		<script>
		var data = {
			pageNo: 1,
			pageSize:10,
			productNo: '', //选择的产品ID
			name: '', //经销商的名称
		};
		var flag;
		var table = document.getElementById("jxsList");
		window.addEventListener('reloadChild', function(event) {
			flag = event.detail.flag;
			data.productNo=event.detail.productNo;
			data.name=event.detail.name;
			pulldownRefresh();
		});
			
		var currentView;
		(function($, doc) {
			$.plusReady(function() {
				currentView=plus.webview.currentWebview();
				flag=currentView.flag;
				data.productNo=currentView.productNo;
				data.name=currentView.name;
				mui.init({
					pullRefresh: {
						container: '#pullrefresh',
						down: {
							 callback: pulldownRefresh
						},
						up: { 
							contentrefresh: '正在加载...',
							callback: pullupRefresh
						}
					}
				});
				
			})
		}(mui, document))
		
		if (mui.os.plus) {
				mui.plusReady(function() {
					setTimeout(function() {
						mui('#pullrefresh').pullRefresh().pullupLoading();
					}, 100);

				});
			} else {
				mui.ready(function() {
					mui('#pullrefresh').pullRefresh().pullupLoading();
				});
			}
			
			//下拉刷新
			function pulldownRefresh() {
				mui('#pullrefresh').pullRefresh().scrollTo(0,0,100);
				var url = flag==1 ?  baseUrl + 'dealersController/get/son/traders.do' : baseUrl + 'dealersController/get/father/traders.do';
				data.pageNo=1;table.innerHTML='';
				mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
				mui('#pullrefresh').pullRefresh().refresh(true);
				ajaxFun.postFun(url,data,'',formList);		 
			}
			
			
		function pullupRefresh() {
			setTimeout(function() {
				var url = flag==1 ?  baseUrl + 'dealersController/get/son/traders.do' : baseUrl + 'dealersController/get/father/traders.do';
				ajaxFun.postFun(url,data,'',formList);	
			},100);
		}
		var total = 0;
		function formList(datalist, params) {		
//			setTimeout(function() {
				data.pageNo++;
				var list = datalist.data.dataList ? datalist.data.dataList : [];
				var html = '';
				if(list.length > 0) {
					total = datalist.data.total > 0 ? datalist.data.total : total;
					for(var i = 0, len = list.length; i < len; i++) {
						if(list[i].name && list[i].mobile){
							var li = formLi(list[i],flag);
							table.appendChild(li);
						}else{
							total--;
						}
					}
					var liLen = document.querySelectorAll('.mui-table-view-cell').length;
					mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
					if(liLen >= total) {
						mui('#pullrefresh').pullRefresh().endPullupToRefresh(true); //参数为true代表没有更多数据了。
					} else {
						mui('#pullrefresh').pullRefresh().endPullupToRefresh(false);
					}
				} else {
					mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
					mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
				}
//			}, 1500);
		}

		function formLi(temp, flag) {
			var li = document.createElement('li');
			li.className = temp.status == 0 ? 'stop mui-table-view-cell' :'mui-table-view-cell';
			temp.statusstr = temp.status == 0 ? '已暂停' : '';
			li.innerHTML = '<p class="mui-navigate-right">' + temp.name + ',' + temp.mobile + '  <span style="float:right;">' + temp.statusstr + '</span></p>';
			li.setAttribute('data-id', flag == 1 ? temp.id : flag == 2 ? temp.parentId : '');
			li.addEventListener('tap', function(event) {
				var tempId = li.getAttribute('data-id');
				var params = {
					id: tempId,
					type: flag, //1表示下级 2表示上级
					productNo: data.productNo
				}
				openWindow('jxsInfo.html', 'jxsInfo', {
					"data": params,
					"flag":flag,
				});
			})
			return li;
		}
		
		
		</script>
	</body>
</html>
